﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Security.Cryptography;
using System.Text;

namespace Directory.Web
{
	/// <summary>
	/// UserDataProxy 的摘要说明
	/// </summary>
	public sealed class UserDataProxy
	{
		private UserDataProxy() { }

		public static Directory.Model.UserInfo GetUserInfo(string username)
		{
			Directory.BLL.User bll = new Directory.BLL.User();
			return bll.GetUserInfo(username);
		}

		public static void DeleteUser(string username)
		{
			Directory.BLL.User bll = new Directory.BLL.User();
			bll.DeleteUser(username);
		}

		public static void LockUser(string username)
		{
			Directory.BLL.User bll = new Directory.BLL.User();
			bll.UpdateUserLockOutSate(username, true);
		}

		public static void UnLockUser(string username)
		{
			Directory.BLL.User bll = new Directory.BLL.User();
			bll.UpdateUserLockOutSate(username, false);
		}

		public static Directory.Model.UserInfo CreateUser(string username, string password, string passwordQuestion, string passwordAnswer, out Directory.Model.UserInfo.ErrorCode errorCode)
		{
			Directory.BLL.User bll = new Directory.BLL.User();
			return bll.CreateUser(username, password, passwordQuestion, passwordAnswer, out errorCode);
		}

		public static bool ValidatePassword(string username, string password)
		{
			Directory.BLL.User bll = new Directory.BLL.User();
			return bll.ValidatePassword(username, password);
		}

		public static void ResetPassword(string username, string newpassword)
		{
			Directory.BLL.User bll = new Directory.BLL.User();
			bll.ResetPassword(username, newpassword);
		}

		public static string GetPasswordQuestion(string username)
		{
			Directory.BLL.User bll = new Directory.BLL.User();
			return bll.GetPasswordQuestion(username);
		}

		public static bool ValidatePasswordAnswer(string username, string passwordQuestion, string passwordAnswer)
		{
			int maxInvalidPasswordAnswerAttempts = 10;
			int passwordAnswerAttemptWindow = 10;
			Directory.BLL.User bll = new Directory.BLL.User();
			return bll.ValidatePasswordAnswer(username, passwordQuestion, passwordAnswer,maxInvalidPasswordAnswerAttempts,passwordAnswerAttemptWindow);
		}

		public static string GeneratePassword(string username)
		{
			string pwd = Guid.NewGuid().ToString().Replace("-","").Remove(10);
			ResetPassword(username, pwd);
			return pwd;
		}

		public static void UpdateuserInfo(Directory.Model.UserInfo userinfo, out Directory.Model.UserInfo.ErrorCode errorCode)
		{
			Directory.BLL.User bll = new Directory.BLL.User();
			bll.UpdateUser(userinfo, out errorCode);
		}
	}
}